<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Classname And Back to top</title>
</head>
<body>
<ul id="Ul1">
    <li></li>
    <li class="cbd"></li>
    <li></li>
    <li class="cbd"></li>
    <li></li>
    <li class="cbd"></li>
    <li></li>
    <li class="cbd"></li>
    <li></li>
    <li class="cbd"></li>
    <li></li>
</ul>
<input id="backTop" value="回到顶部" type="button"/>
<input type="button" id="btn" value="打开新窗口"/>
<script type="text/javascript">
    function getByClass(oParent,oClass)
    {
        var oElc=oParent.getElementsByTagName('*');
        var i=0;
        var oResult=[];
        for (i=0;i<oElc.length;i++)
        {
            if (oElc[i].className==oClass){
                oResult.push(oElc[i]);
            }
        }
        return oResult;
    }

    window.onload=function () {
        //
        var oUl = document.getElementById('Ul1');
        //var oLi = oUl.getElementsByTagName('li');
        var oBtn1 = document.getElementById('btn');
        var oCbd = getByClass(oUl, 'cbd');
        var oBackTop = document.getElementById('backTop');
        var timer=null;
        var bSys=true;
        var i = 0;
        window.onscroll=function()
        {
            if(!bSys){
                clearInterval(timer);
            }
            bSys=false;
        }
        for (i = 0; i < oCbd.length; i++) {
            oCbd[i].style.backgroundColor = 'green';
        }
        oBtn1.onclick = function () {
            //window.open('https://start.firefoxchina.cn/');
            alert(window.navigator.userAgent);
        }

        oBackTop.onclick = function () {
            timer = setInterval(
                function () {
                    var oScrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                    var oSpeed = Math.floor(-oScrollTop / 8);
                    if (oScrollTop == 0) {
                        clearInterval(timer);
                    }
                    bSys = true;
                    document.documentElement.scrollTop = oScrollTop + oSpeed;
                }, 30
            )
        }

    }
</script>
<style>
    body{
        min-height: 8000px;
    }
    #backTop{
        position: fixed;
        bottom: 30px;
        right: 30px;
    }
</style>
</body>
</html>
